package ModelLayer;
import java.util.ArrayList;

public class Product //class use to make product-objects
{
    private static Product instance;
    public ArrayList<Serialnumber> serialnumberList;
    
    private String productName;
    private int productId;
    private String description;
    private double singlePrice;
    private boolean inStorage;

    /**
     * Constructor for objects of class Vare
     */
    public Product(String productName, int productId, String description, double singlePrice, boolean inStorage)
    {
        // initialise instance variables
        this.productName = productName;
        this.productId = productId;
        this.description = description;
        this.singlePrice = singlePrice;
        this.inStorage = inStorage;
        
        serialnumberList = new ArrayList<Serialnumber>();
    }

    /**
     * An example of a method - replace this comment with your own
     * 
     * @param  y   a sample parameter for a method
     * @return     the sum of x and y 
     */
    public void updateProduct(String productName, int productId, String description, double singlePrice)  //used to update product
    {
        this.productName = productName;
        this.productId = productId;
        this.description = description;
        this.singlePrice = singlePrice;
        inStorage();
    }
    
    public String getProductName() //used to get the product name
    {
        return productName;
    }
    
    public String getProductId() // used to get the product id
    {
        String pId = ""+productId;
        return pId;
    }
    
    public void addSerialnumber(long serialnumber)  // used to add a serialnumber to the product
    {
        Serialnumber newSerialnumber = new Serialnumber(serialnumber);
        serialnumberList.add(newSerialnumber);
        System.out.println("Serialnumber has been added!");
        
        inStorage();
    }
    
    public boolean inStorage()  //checks if the product is in storage, by looking at the serial list
    {
        if(serialnumberList.size()>=0)
        {
            inStorage = true;
        }
        else
        {
            inStorage = false;
        }
        
        return inStorage();
    }
    
    public void showInfo()  //shows info about the product
    {
        inStorage();
        System.out.println("Product name: "+productName);
        System.out.println("Product ID: "+productId);
        System.out.println("Description: "+description);
        System.out.println("Price: "+singlePrice);
        System.out.println("In storage "+inStorage);
    }
    
    public double getPrice()  //used to get the price of the product
    {
        return singlePrice;
    }
}
